﻿

using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;

namespace Code.UI
{
    [RequireComponent((typeof(Image)))]
    public class TabButton : MonoBehaviour, IPointerEnterHandler, IPointerClickHandler, IPointerExitHandler, ISelectHandler, ISubmitHandler, IDeselectHandler
    {
        public TabGroup TabGroup;
        public Image Background;
        public UnityEvent onTabSelected;
        public UnityEvent onDeslected;
        private void Awake()
        {
            Background = GetComponent<Image>();
            //TabGroup.Subscribe(this);
        }

        public void OnPointerEnter(PointerEventData eventData)
        {
            TabGroup.OnTabEnter(this);
        }

        public void OnPointerClick(PointerEventData eventData)
        {
            TabGroup.OnTabSelected(this);
        }

        public void OnPointerExit(PointerEventData eventData)
        {
            TabGroup.OnTabExit(this);
        }

        public void OnSelect(BaseEventData eventData)
        {
            TabGroup.OnTabEnter(this);
            Debug.Log("You are hovering the button");
        }

        public void OnSubmit(BaseEventData eventData)
        {
            TabGroup.OnTabSelected(this);
            Debug.Log("You are no more hovering the button");
        }

        public void OnDeselect(BaseEventData eventData)
        {
            TabGroup.OnTabExit(this);
            Debug.Log("You selected the button");
        }


        public void Select()
        {
            onTabSelected?.Invoke();
        }
        public void Deselect()
        {
            onDeslected?.Invoke();
        }

       
    }
}
